﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace C1
{
    class node<T> {
        public T data { set; get; }
        public node<T> next { set; get; }
        public node(T t)
        {
            data = t;
            next = null;
        }
    }
    class nodeList<T>
    {
        private node<T> head;
        private node<T> tail;
        public node<T> gethead()
        {
            return head;
        }
        public nodeList()
        {
            head = tail = null;
        }
        public void add(T t)
        {
            node<T> n = new node<T>(t);
            if (tail == null)
            {
                head = tail = n;
            }
            else
            {
                tail.next = n;
                tail = n;
            }
        }

        public void myforeach(Action<T> a)
        {
            node<T> my = head;
            while (my != null)
            {
                a(my.data);
                my = my.next;
            }
        }

    }
    class Program
    {
        static void Main(string[] args)
        {
            nodeList<int> intlist = new nodeList<int>();
            for(int i = 0; i < 10; i++)
            {
                intlist.add(i);
            }
            intlist.myforeach(s => Console.WriteLine(s));

            int sum = 0;
            intlist.myforeach(s => sum += s);
            Console.WriteLine("sum=" + sum);

            int max = intlist.gethead().data;
            intlist.myforeach(s => max=max>s?max:s);
            Console.WriteLine("max=" + max);

            int min = intlist.gethead().data;
            intlist.myforeach(s => min = min < s ? min : s);
            Console.WriteLine("min=" + min);
            Console.ReadLine();
        }
    }
}
